package com.ccbft.msgcenter.mc.filter.service.impl;

import com.ccbft.msgcenter.mc.filter.entity.ChainNode;
import com.ccbft.msgcenter.mc.filter.entity.Topics;
import com.ccbft.msgcenter.mc.filter.mapper.TopicsMapper;
import com.ccbft.msgcenter.mc.filter.service.IChainInstanceService;
import com.ccbft.msgcenter.mc.filter.service.IChainNodeService;
import com.ccbft.msgcenter.mc.filter.service.ITopicsService;
import com.ccbft.msgcenter.mc.filter.vo.ChainInstanceVo;
import com.ccbft.msgcenter.mc.filter.vo.TopicVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author frank
 * @since 2019-07-25
 */
@Service
public class TopicsServiceImpl extends ServiceImpl<TopicsMapper, Topics> implements ITopicsService {

	@Autowired
	IChainInstanceService chainInstanceService;
	
	@Autowired
	IChainNodeService chainNodeService;
	
	@Override
	public boolean addTopic(TopicVo vo) {
		boolean ret = false;
		ret = this.save(vo);
		ChainInstanceVo chain = vo.getChainInstance();
		if(chain!=null) {
			chainInstanceService.save(chain);
			List<ChainNode> nodes = chain.getChainNodeList();
			if(nodes!=null) {
				chainNodeService.saveBatch(nodes);
			}
		}
		return ret;
	}

}
